package com.chinaunicom.gateway.infrastructure.gateway;

import com.chinaunicom.api.IMemberFacadeApi;
import com.chinaunicom.api.dto.MemberDTO;
import com.chinaunicom.common.constants.Constants;
import com.chinaunicom.common.result.JsonResult;
import com.chinaunicom.gateway.domain.gateway.IMemberGateway;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * @author guomenghuai
 * @date 2024/1/9
 * @Description
 */
@Service
public class MemberGateway implements IMemberGateway {

    @Reference
    private IMemberFacadeApi memberFacadeApi;

    @Override
    public MemberDTO info(String token) {
        JsonResult<MemberDTO> jsonResult = memberFacadeApi.info(token);
        if (!StringUtils.equals(Constants.SUCCESS_CODE, jsonResult.getErrorCode()) || Objects.isNull(jsonResult.getData())) {
            throw new RuntimeException("调用会员服务失败");
        }
        return jsonResult.getData();
    }

}
